<%-- 
    Document   : UserConfiguration
    Created on : Nov 25, 2011, 12:33:57 PM
    Author     : ferru001
--%>
<%@ include file="/WEB-INF/views/includes.jsp" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="com.cheapflix.beans.RecommendedDVD" %>
<%@ page import="com.cheapflix.beans.User" %>
<%@ page import="com.cheapflix.beans.DVD" %>
<%@ page import="java.util.Map" %>
<%@ page import="java.util.HashMap" %>
<%@ page import="java.util.Set" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Profile Page for <c:out value="${user.nameFirst}"/> <c:out value="${user.nameLast}"/></title>
        <link rel="stylesheet" type="text/css" href="/cheapflix/css/style.css" />
        <script type="text/javascript" src="<%=request.getContextPath()%>/js/login.js"/>
        <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.7.0/jquery.min.js"></script>
    </head>
    <body>
        <div class="outer">
            <%@ include file="/WEB-INF/views/header.jsp" %>
            <div class="row rowstyle">
                <c:choose>
                    <c:when test="${sameUser}">
                        <h1>Update user information</h1>
                        <form action="/cheapflix/updateuserinfo/" method="POST" id="loginform" class="loginform">
                            <input type="hidden" name="userId" value="<c:out value="${me.id}"/>"/>
                            <label>First Name:</label><input type="text" name="nameFirst" value='<c:out value="${me.nameFirst}"/>' class="text"/><br/>
                            <label>Last Name:</label><input type="text" name="nameLast" value='<c:out value="${me.nameLast}"/>'  class="text"/><br/>
                            <label>Password:</label><input type="password" name="password"   class="text"/><br/>
                            <c:if test="${param.msg != null}">
                                <div style="color:green"><c:out value="${param.msg}"/></div>
                            </c:if>
                            <div style="width:100%;text-align:left;margin-left:50px;"><input type="submit" value="Update" class="submit"/></div>

                        </form>
                    </c:when>
                    <c:otherwise>
                        <h2>Profile for <span style="background:lightcyan"><c:out value="${user.username}"/></span></h2><br/>
                        <h3>Name: <c:out value="${user.nameFirst}"/> <c:out value="${user.nameLast}"/></h3>
                    </c:otherwise>
                </c:choose>
                <c:if test="${isFriend == false}">
                    <a href='/cheapflix/frienduser/<c:out value=""/>'>Friend <c:out value="${user.nameFirst}"/></a>
                </c:if>

                <c:choose>
                    <c:when test="${fn:length(user.friends) > 0 }">
                        <h2>
                            Flix Friends:
                        </h2>
                        <div style="width:100%;text-align:center;">
                            <table class="stdTable">
                                <tr><th>Profile</th><th>Unfriend</th><th>username</th><th>Name</th></tr>
                                <c:forEach var="friend" items="${user.friends}">
                                    <tr>
                                        <td> <a href="/cheapflix/users/<c:out value="${friend.value.id}"/>">View Profile</a></td> <td><a href="/cheapflix/unfriend/<c:out value="${friend.value.id}"/>">unfriend</a></td><td><c:out value="${friend.value.username}"/></td><td><c:out value="${friend.value.nameFirst}"/> <c:out value="${friend.value.nameLast}"/></td>
                                    </tr>
                                </c:forEach>
                            </table><br/>
                        </div>
                    </c:when>
                    <c:otherwise>
                        <div class="message"><h3>This user has no FlixFriends</h3></div>
                    </c:otherwise>
                </c:choose>


                <div class="message">This user's Flick recommendations</div>
                <div class="searchResults">
                    <% int i = 0;
                      Set<DVD> recommendedDVDs = (Set<DVD>)request.getAttribute("recommendedDVDs");
                    %>

                    <c:forEach items="${recommendedDVDs}" var="recommendedDVD">
                        <%
                            
                            String cssClass = "";
                            if (i < recommendedDVDs.size()) {
                                cssClass = "SingleResult";
                            }
                        %>
                        <div class="<%=cssClass%>">
                            <a href="/cheapflix/searchId?id=<c:out value="${recommendedDVD.id}"/>"><c:out value="${recommendedDVD.title}"/></a>
                        </div>
                    </c:forEach>
                </div>

                <a href="/cheapflix/usersearch?q=">Search for users</a>
            </div>
            <%@ include file="/WEB-INF/views/footer.jsp" %>
        </div>
    </body>
</html>
